	function initialize() {    	
    	map = new google.maps.Map(document.getElementById("map_canvas"), {
    			zoom: 18,
			
    			center: new google.maps.LatLng(45.912543, 6.125897),
			
    			mapTypeId: google.maps.MapTypeId.ROADMAP
			
          });
    	
		if (navigator.geolocation) {
	    	watchPlayerPosition();

		}else {
			alert("Votre navigateur ne prend pas en compte la géolocalisation HTML5");
		
		}
	  
    }

	function watchPlayerPosition()  {
		var watchId = navigator.geolocation.getCurrentPosition(successPlayerPosition,
		                                  					errorCallback,
		                                  						{enableHighAccuracy:true,
		                                  						timeout:10000,
		                                  						maximumAge:0});
	
	}
	
	function successPlayerPosition(position){
		map.center = new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
		addMainPlayer(position);
	
	}
	
	function addMainPlayer(position) {
	       you = new google.maps.Marker({
	          	position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
	          	map: map,
	          	title: 'you',
	  			icon : 'images/mainRebel.png',
	      });
		
	}
	
	function addSafeHaven(id, lat, lng, faction, playersIn, playerFaction) {
		var icon = 'images/rebelsSafeHaven.png';

		if('Oppressors' == faction){
			icon = 'images/oppressorsSafeHaven.png';
		};
		
      		window['safeHaven_' + id] = new google.maps.Marker({
      			position: new google.maps.LatLng(lat,lng),
      			map: map,
      			title: 'safeHaven_' + id,
      			icon : icon,
      		});

	      google.maps.event.addListener(window['safeHaven_' + id], 'click', function() {
	          var position = this.getPosition();

	  	      window['infowindow' + id] = new google.maps.InfoWindow({
		    	  content: ""
		      });
	          
	  	      if (faction != playerFaction) {
	  	    	  if (1 < playersIn) {
			    	  window['infowindow' + id].setContent("<span>" + playersIn + " Joueurs dans le refuge, revenez plus nombreux !</span>");
	  	    	  
	  	    	  }else {
			    	  window['infowindow' + id].setContent("<span>Le refuge est libre !</span><br /><a href='capture.php?id=" + id + "'>Capturer le refuge !</a>");
	  	    		  
	  	    	  }
	  	    	  
	  	      }else {
		    	  window['infowindow' + id].setContent("Refuge rebel");
	  	    	  
	  	      }
	    	  window['infowindow' + id].open(map, this);
	      });
		
	}
	
	function addRebel(imei, lat, lng) {
		var icon = 'images/rebel.png';
		addPlayer(imei, icon, lat, lng);
		
	}
	
	function addOppressor(imei, lat, lng, mainPLayer) {
		var icon = 'images/oppressor.png';
		player = addPlayer(imei, icon, lat, lng);
		
		google.maps.event.addListener(player, 'click', function() {
	  	      var infowindow = new google.maps.InfoWindow({
		    	  content: ""
		      });
	          
	  	      infowindow.setContent("<a href='duel.php'>Provoquer en duel !</a>");
	  	    	  

	    	  infowindow.open(map, this);
	      });
		
	}
	
	function addPlayer(imei, icon, lat, lng) {
	       player = new google.maps.Marker({
	          	position: new google.maps.LatLng(lat, lng),
	          	map: map,
	          	title: 'player_' + imei,
	  			icon : icon,
	      });
	       
	       return player;
		
	}
	
	function make_lien(type,destination,texte_lien,div_conteneur)
	{
		var nouveau_lien=document.createElement('a');
	        nouveau_lien.href=type+texte_lien;
	        nouveau_lien.innerHTML=texte_lien;
	        document.getElementDyid(div_conteneur).appendChild(nouveau_lien);
	}
	

		 
	function stopGeolocation (){
		navigator.geolocation.clearWatch(watchId);
	}     
		 

		 
	function errorCallback(error){
		switch(error.code){
			case error.PERMISSION_DENIED:
				alert("L'utilisateur n'a pas autorisé l'accès à sa position");
				break;
			case error.POSITION_UNAVAILABLE:
				alert("L'emplacement de l'utilisateur n'a pas pu être déterminé");
				break;
			case error.TIMEOUT:
				alert("Le service n'a pas répondu à temps");
				break;
		}

	};
	
	

	
